// 项目中的vuex管理性文件
import Vue from "vue";//引入vue对象
import Vuex from "vuex";//引入vuex对象
import {menus} from "@/api/menus.js";
import RouterMain from "@/router";// 引入路由对象

import {setStore ,RouterRec} from "@/config/config";
Vue.use(Vuex);//vuex注册
const state ={
   
}
const getters ={
 
}
const actions ={
  
}
const mutations={
    meauSave(){
        menus().then(res =>{
            console.log(res);
            let {data} = res;
            // 把获得菜单放到缓存中防止万一
            
        //    路由 静态路由 动态路由路由是后端返回的 我们前端进行封装处理成我们自己的路由对象
            let routersObjList = [
               {
                    path:"/home",
                    name:"home",
                    component:()=>import(`@/page/home/home`),
                    redirect:`/${data[0].path}`,
                    children:RouterRec(data ,1)
               }
           ] 
           console.log(routersObjList)
           setStore("menusList" ,JSON.stringify(routersObjList));
           RouterMain.options.routers = routersObjList;
           RouterMain.addRoutes(routersObjList)
           
        })
    }
}
export default new Vuex.Store({
   
        state,
        getters,
        mutations,
        actions,
        modules:{
           
        }
})